云飞扬 - 个人博客

windows nginx natapp

2018-04-27

实现目标

  1. 通过nginx实现本地资源代理
  2. https 学习及使用
  3. 方便本地前端服务调试

相关环境

  • windows 7 64
  • nginx v 1.6
  • natapp
  • phpStudy
  • 阿里云

基本操作

线上配置

  1. 注册个人域名
  2. 注册natapp
  3. 域名和natapp进行绑定

nginx 配置

常用命令

1
2
3
4
5
6
nginx -s stop 强制关闭 
nginx -s quit 安全关闭
nginx -s reload 改变配置文件的时候,重启nginx工作进程,来时配置文件生效
nginx -t 测试是否成功

.\nginx.exe -t # windows 下要添加.\

http 代理配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 静态页面
location /html {
alias F:/HTML/year;
}
# 端口代理
location /demo {
proxy_pass http://127.0.0.1:6061;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# php环境代理
location ~ \.php(.*)$ {
root E:/WWW;# 这里是站点的根目录
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}

https 代理配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
server {
listen 443;
server_name localhost;

ssl on;
ssl_certificate https/214009859140175.pem; # ssl 加密文件
ssl_certificate_key https/214009859140175.key; # ssl 加密文件

ssl_session_timeout 5m;

ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

location / {
root html;
index index.html index.htm;
}

# 静态页面
location /html {
alias F:/HTML/year;
}

# https 功能测试
location /https-demo {
proxy_pass http://127.0.0.1:6061;
}

}

phpStudy 列表

phpStudy 配置

Apache 服务配置

Apache 环境配置

php 配置

1
php-cgi.exe -b 127.0.0.1:9000-c E:\WWW

不运行上面代码,无法访问php

nssm 开机启动&后台运行

1
2
3
4
nssm install natapp # 安装服务
nssm edit natapp # 编辑服务器名
nssm restart natapp # 重启natapp服务
nssm remove natapp # 删除XX服务

nssm 开机启动&后台运行
自定义服务

注意事项

  1. window 执行exe

    1
    .\n
  2. https 加密文件

    这两块必须要有的,可以到阿里云去申请。

    1
    2
    ssl_certificate      https/214009859140175.pem; # ssl 加密文件
    ssl_certificate_key https/214009859140175.key; # ssl 加密文件
  3. 阿里云【管理控制台】下【证书服务】

参考

Tags: tools
使用支付宝打赏
使用微信打赏

若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏

扫描二维码,分享此文章